
package com.enjoyiot.module.bms.dal.mysql.device;

import cn.hutool.core.util.ObjectUtil;
import com.enjoyiot.framework.common.pojo.PageResult;
import com.enjoyiot.framework.mybatis.core.mapper.BaseMapperX;
import com.enjoyiot.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.enjoyiot.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.enjoyiot.module.bms.controller.admin.asset.vo.AssetPageReqVO;
import com.enjoyiot.module.bms.controller.admin.device.vo.BmsDevice;
import com.enjoyiot.module.bms.controller.admin.device.vo.BmsDevicePageReqVO;
import com.enjoyiot.module.bms.controller.admin.device.vo.BmsDeviceRespVO;
import com.enjoyiot.module.bms.dal.dataobject.AssetDO;
import com.enjoyiot.module.bms.dal.dataobject.BmsDeviceDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface BmsDeviceMapper extends BaseMapperX<BmsDeviceDO> {

    default PageResult<BmsDevice> selectPage(BmsDevicePageReqVO reqVO) {
        MPJLambdaWrapperX<BmsDeviceDO> q = new MPJLambdaWrapperX<BmsDeviceDO>()
                .selectAll(BmsDeviceDO.class)
                .selectAs(AssetDO::getAssetName, BmsDevice::getAssetName)
                .selectAs(AssetDO::getAssetSn, BmsDevice::getAssetSn)
                .selectAs(AssetDO::getLocation, BmsDevice::getLocation)
                .selectAs(AssetDO::getAssetModel, BmsDevice::getAssetModel)
                .selectAs(AssetDO::getAssetBrand, BmsDevice::getAssetBrand)
                .eqIfPresent(BmsDeviceDO::getDeviceStatus, reqVO.getDeviceStatus())
                .orderByDesc(BmsDeviceDO::getId);
        q.leftJoin(AssetDO.class, AssetDO::getId, BmsDeviceDO::getAssetId);
        q.likeIfExists(AssetDO::getAssetName, reqVO.getAssetName());
        return selectJoinPage(reqVO, BmsDevice.class, q);
    }
}
